import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
import vueTsEslintConfig from '@vue/eslint-config-typescript'
import prettier from 'eslint-plugin-prettier'
import pluginVue from 'eslint-plugin-vue'

export default [
  {
    name: 'app/files-to-lint',
    files: ['**/*.{ts,mts,tsx,vue}'],
  },

  {
    name: 'app/files-to-ignore',
    ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
  },

  ...pluginVue.configs['flat/essential'],
  ...vueTsEslintConfig({
    // 放宽TypeScript的严格检查
    rules: {
      '@typescript-eslint/no-explicit-any': 'off',
      '@typescript-eslint/no-unused-vars': 'warn',
      '@typescript-eslint/explicit-function-return-type': 'off',
      '@typescript-eslint/no-inferrable-types': 'off',
      '@typescript-eslint/prefer-const': 'warn',
      '@typescript-eslint/no-non-null-assertion': 'off',
      '@typescript-eslint/ban-ts-comment': 'warn',
    },
  }),

  // Prettier配置 - 设置为警告级别（不会阻止程序运行）
  {
    plugins: {
      prettier: prettier,
    },
    rules: {
      // Prettier规则设置为警告级别
      'prettier/prettier': 'warn',
      
      // 其他格式相关规则也设置为警告级别
      'indent': ['warn', 2],
      'quotes': ['warn', 'single'],
      'semi': ['warn', 'never'],
      'comma-dangle': ['warn', 'es5'],
      'no-trailing-spaces': 'warn',
      'eol-last': 'warn',
      'no-multiple-empty-lines': ['warn', { 'max': 1, 'maxEOF': 0 }],
      'object-curly-spacing': ['warn', 'always'],
      'array-bracket-spacing': ['warn', 'never'],
      'space-before-function-paren': ['warn', 'never'],
      'keyword-spacing': ['warn', { 'before': true, 'after': true }],
      'space-infix-ops': 'warn',
      'arrow-spacing': 'warn',
      'template-curly-spacing': ['warn', 'never'],
      'comma-spacing': ['warn', { 'before': false, 'after': true }],
      'key-spacing': ['warn', { 'beforeColon': false, 'afterColon': true }],
      'no-multi-spaces': 'warn',
      'no-whitespace-before-property': 'warn',
      'object-property-newline': ['warn', { 'allowAllPropertiesOnSameLine': true }],
      'operator-linebreak': ['warn', 'before'],
      'function-paren-newline': ['warn', 'consistent'],
      'array-element-newline': ['warn', 'consistent'],
      'object-curly-newline': ['warn', { 'consistent': true }],
      
      // CSS相关规则
      'vue/component-name-in-template-casing': ['warn', 'PascalCase'],
      'vue/component-definition-name-casing': ['warn', 'PascalCase'],
      'vue/component-options-name-casing': ['warn', 'PascalCase'],
      'vue/custom-event-name-casing': ['warn', 'camelCase'],
      'vue/define-macros-order': ['warn', {
        order: ['defineProps', 'defineEmits']
      }],
      'vue/html-comment-content-spacing': ['warn', 'always'],
      'vue/no-unused-refs': 'warn',
      'vue/no-useless-v-bind': 'warn',
      'vue/padding-line-between-blocks': ['warn', 'always'],
      'vue/prefer-separate-static-class': 'warn',
    },
  },

  // 跳过与prettier冲突的ESLint规则
  skipFormatting,
]
